//
//  MVSecendScrollView.m
//  testCocoPods1.0
//
//  Created by ChenJs92 on 16/11/15.
//  Copyright © 2016年 chenjs92. All rights reserved.
//

#import "MVSecendScrollView.h"
#import "MVSecendScrooViewMode.h"
#import "MVSecendHeadView.h"
#import "mVSecendActiView.h"
#import "MVSecendListView.h"
@interface MVSecendScrollView()
@property (strong, nonatomic) MVSecendScrooViewMode *viewMode;
@property (strong, nonatomic) MVSecendHeadView *headView;
@property (strong, nonatomic) mVSecendActiView *actiView;
@property (strong, nonatomic) MVSecendListView *listView;
@property (strong, nonatomic) UIScrollView *baseScrollView;
@end

@implementation MVSecendScrollView
-(instancetype)initWithViewModel:(id<MVViewModelProtocol>)viewModel{
    self.viewMode = (MVSecendScrooViewMode *)viewModel;
    return [super initWithViewModel:viewModel];
}

-(void)yd_setupViews{
    
    [self addSubview:self.baseScrollView];
    [self.baseScrollView addSubview:self.headView];
    [self.baseScrollView addSubview:self.actiView];
    [self.baseScrollView addSubview:self.listView];
    
    [self setNeedsUpdateConstraints];
    [self updateConstraintsIfNeeded];
}
-(void)updateConstraints{
    WS(weakSelf)
    CGFloat paddingEdge = 10;
    UIScreen *main = [UIScreen mainScreen];
    CGFloat screenWidth = main.bounds.size.width;
    
    [self.baseScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(weakSelf);
    }];
    
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
        make.width.mas_equalTo(screenWidth);
        make.height.mas_equalTo(120);
    }];
    
    [self.actiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(80);
        make.width.mas_equalTo(screenWidth);
        make.top.mas_equalTo(weakSelf.headView.mas_bottom).offset(paddingEdge);
    }];
    
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(screenWidth);
        make.height.mas_equalTo(1000);
        make.bottom.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(weakSelf.actiView.mas_bottom).offset(paddingEdge);
    }];
    [super updateConstraints];
}
-(MVSecendHeadView *)headView{
    if (!_headView) {
        _headView = [[MVSecendHeadView alloc] initWithViewModel:self.viewMode];
    }
    return _headView;
}
-(mVSecendActiView *)actiView{
    if (!_actiView) {
        _actiView = [[mVSecendActiView alloc] initWithViewModel:self.viewMode];
    }
    return _actiView;
}
-(MVSecendListView *)listView{
    if (!_listView) {
        _listView = [[MVSecendListView alloc] initWithViewModel:self.viewMode];
    }
    return _listView;
}
-(MVSecendScrooViewMode *)viewMode{
    if (!_viewMode) {
        _viewMode = [[MVSecendScrooViewMode alloc] init];
    }
    return _viewMode;
}
-(UIScrollView *)baseScrollView{
    if (!_baseScrollView) {
        _baseScrollView = [[UIScrollView alloc] initWithFrame:self.frame];
        _baseScrollView.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
    }
    return _baseScrollView;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
